<%--                                                                       --%>
<%-- Copyright (c) 2003-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import="com.broadvision.web.util.ViewDynaBean" %>
<%@ page import="org.apache.commons.beanutils.PropertyUtils" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<script language="javascript" src="<%=request.getContextPath()%>/mt/js/date.js">
</script>


<script language="JavaScript">

  function doNext(theform) {
    theform.action='<html:rewrite page="/bp/taskDelegateNew.do" />';
    return true ;
  }

  function doFinish(theform) {
    theForm.formAction.value="editCurrent";
    theform.action='<html:rewrite page="/bp/taskDelegateNew.do" />';
    return true;
  }

  function isFormCancelOK(theForm) {
    //var ok = confirm('<bean:message key="confirmCancel"  bundle="bp.messages"/>');
    var ok = true;
    if (ok && theForm != null) {
      var fromSet = theForm.fromSet.value;
      if ("true" == fromSet) {
        theForm.action='<html:rewrite page="/bp/delegationList.do"/>';
      }
      else {
        theForm.action='<html:rewrite page="/bp/userSearch.do"/>';
      }
      theForm.submit();
    }
    return ok ;
  }

</script>


<% 
  java.util.HashMap map = new java.util.HashMap();

  map.put("userId", request.getParameter("userId"));
  map.put("formAction", request.getParameter("formAction"));
  map.put("type", request.getParameter("type"));
  map.put("description", request.getParameter("description"));
  map.put("endRadio", request.getParameter("endRadio"));

  String timeFilter = request.getParameter("timeFilter");
  map.put("timeFilter", (null == timeFilter) ? "ALL" : timeFilter);

  String fromSet = request.getParameter("fromSet");
  map.put("fromSet", (null == fromSet) ? "false" : fromSet);

  String delegationOid = request.getParameter("delegationOid");
  map.put("delegationOid", (null == delegationOid) ? "-1" : delegationOid);

  String delegatorId = request.getParameter("delegatorId");
  map.put("delegatorId", (null == delegatorId) ? "-1" : delegatorId);

  String delegateId = request.getParameter("delegateId");
  map.put("delegateId", (null == delegateId) ? "-1" : delegateId);

  String firstHit = request.getParameter("firstHit");
  map.put("firstHit", (null == firstHit) ? "true" : firstHit);

  map.put("start.month", request.getParameter("start.month"));
  map.put("start.day", request.getParameter("start.day"));
  map.put("start.year", request.getParameter("start.year"));
  map.put("end.month", request.getParameter("end.month"));
  map.put("end.day", request.getParameter("end.day"));
  map.put("end.year", request.getParameter("end.year"));

  map.put("firstNameFrom", request.getParameter("firstNameFrom"));
  map.put("lastNameFrom", request.getParameter("lastNameFrom"));
  map.put("fullNameFrom", request.getParameter("fullNameFrom"));
  map.put("userAliasFrom", request.getParameter("userAliasFrom"));

  map.put("firstNameTo", request.getParameter("firstNameTo"));
  map.put("lastNameTo", request.getParameter("lastNameTo"));
  map.put("fullNameTo", request.getParameter("fullNameTo"));
  map.put("userAliasTo", request.getParameter("userAliasTo"));

  if ((null != delegationOid) && !delegationOid.equals("-1")) {
    map.put("oldStart.month", request.getParameter("oldStart.month"));
    map.put("oldStart.day", request.getParameter("oldStart.day"));
    map.put("oldStart.year", request.getParameter("oldStart.year"));
    map.put("oldStart.hour", request.getParameter("oldStart.hour"));
    map.put("oldStart.minute", request.getParameter("oldStart.minute"));
    map.put("oldStart.ind", request.getParameter("oldStart.ind"));
    map.put("oldEnd.month", request.getParameter("oldEnd.month"));
    map.put("oldEnd.day", request.getParameter("oldEnd.day"));
    map.put("oldEnd.year", request.getParameter("oldEnd.year"));
    map.put("oldEnd.hour", request.getParameter("oldEnd.hour"));
    map.put("oldEnd.minute", request.getParameter("oldEnd.minute"));
    map.put("oldEnd.ind", request.getParameter("oldEnd.ind"));
  }
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<!-- Zone 5 starts here.  -->
<html:javascript formName="delegationEditForm"/>

<html:form action="/bp/taskDelegateNew.do" onsubmit="return validateDelegationEditForm(this);">

<html:hidden property="userId" />
<html:hidden property="timeFilter" />
<html:hidden property="fromSet" />
<html:hidden property="delegationOid" />
<html:hidden property="delegatorId" />
<html:hidden property="delegateId" />
<html:hidden property="type" value="task"/>

<logic:equal name="delegationEditView" property="isCurrent" value="true">
  <html:hidden property="formAction" value="editCurrent"/>
</logic:equal>

<logic:equal name="delegationEditView" property="isCurrent" value="false">
  <html:hidden property="formAction" value="next"/>
</logic:equal>

<logic:notEqual name="delegationEditForm" property="delegationOid" value="-1">
 <html:hidden property="oldStart.month" />
 <html:hidden property="oldStart.day" />
 <html:hidden property="oldStart.year" />
 <html:hidden property="oldStart.hour" />
 <html:hidden property="oldStart.minute" />
 <html:hidden property="oldStart.ind" />
 <html:hidden property="oldEnd.month" />
 <html:hidden property="oldEnd.day" />
 <html:hidden property="oldEnd.year" />
 <html:hidden property="oldEnd.hour" />
 <html:hidden property="oldEnd.minute" />
 <html:hidden property="oldEnd.ind" />
</logic:notEqual>

<html:hidden property="firstNameFrom" />
<html:hidden property="lastNameFrom" />
<html:hidden property="fullNameFrom" />
<html:hidden property="userAliasFrom" />

<html:hidden property="firstNameTo" />
<html:hidden property="lastNameTo" />
<html:hidden property="fullNameTo" />
<html:hidden property="userAliasTo" />

<%
  ViewDynaBean delegationEditView = (ViewDynaBean) request.getAttribute("delegationEditView");
  String delegatorName = (String) PropertyUtils.getSimpleProperty(delegationEditView, "delegatorName");
  StringBuffer pageTitle = new StringBuffer("bp.user.userDelegationEdit.pageTitle.task");
%>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean:message key="bp.package.contentArea" bundle="bp.messages"/>">
  <tr>
    <td valign="top" width="100%">		    

      <div class="pageTitle">
 	<logic:notEmpty name="delegationEditView" property="delegatorName">
          <bean:message key="<%=pageTitle.toString()%>" arg0="<%=delegatorName%>"  bundle="bp.messages"/>
        </logic:notEmpty>
	<logic:empty name="delegationEditView" property="delegatorName">
          <bean:message key="menu.userManagement.delegateTasks" bundle="bp.messages"/>
        </logic:empty>
      </div>

      <!-- pageTab -->
      <div class="errorMessage">
        <logic:notEmpty name="delegationEditForm" property="errorMessage">
          <bean:write name="delegationEditForm" property="errorMessage"/>
        </logic:notEmpty>
        <logic:empty name="delegationEditForm" property="errorMessage">
          <html:errors bundle="bp.messages"/>
        </logic:empty>		
      </div>

      <%@include file="/mc/common/pagetab.jsp" %>
      <!-- end of PageTab -->			

      <div class="pageSubtitle">
          <span class="left"><bean:message key="bp.user.userDelegationEdit.pageSubtitle.selectTimePeriod" bundle="bp.messages"/></span>
          <span class="right">&nbsp;</span>
      </div> 

        <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Select time period">
          <tr> 
            <td class="label" width="20%">
              <bean:message key="bp.user.userDelegationEdit.label.start.required" bundle="bp.messages"/>
            </td>
            <td class="labelField" colspan="3">
              <logic:equal name="delegationEditView" property="isCurrent" value="false">
                <bvhtml:date name="delegationEditForm" property="start"
                   onChangeMonth="onChangeMonth"
onChangeYear="onChangeYear" noblank="true"/>
                <a href="JavaScript:datePopup(
                    '<html:rewrite page="/mt/calendar.do"/>',
                    'delegationEditForm','start')">
                  <img src="<%=request.getContextPath()%>/bp/images/action/calendar.gif"
                       width="22" height="22"
                       alt='<bean:message key="bp.user.userDelegationEdit.chooseDate"  bundle="bp.messages"/>'
                       title='<bean:message key="bp.user.userDelegationEdit.chooseDate"  bundle="bp.messages"/>'
                       border="0" align="absmiddle"/>
                </a>
              </logic:equal>
              <logic:equal name="delegationEditView" property="isCurrent" value="true">
                <html:hidden property="start.month" />
                <html:hidden property="start.day" />
                <html:hidden property="start.year" />
                <html:hidden property="start.hour" />
                <html:hidden property="start.minute" />
                <html:hidden property="start.ind" />
                <logic:equal name="delegationEditView" property="showStartTime" value="true">
                  <bean:write name="delegationEditForm" property="start.date"
                              formatKey="format.datetime.short"  bundle="mc.messages"/>
                </logic:equal>
                <logic:equal name="delegationEditView" property="showStartTime" value="false">
                  <bean:write name="delegationEditForm" property="start.date"
                              formatKey="format.date.medium"  bundle="mc.messages"/>
                </logic:equal>
              </logic:equal>
            </td>
          </tr>
          <tr> 
            <td class="label" width="20%">
              <bean:message key="bp.user.userDelegationEdit.label.end.required" bundle="bp.messages"/>
            </td>
            <td class="labelField" colspan="3">
              <logic:equal name="delegationEditForm" property="delegationOid" value="-1">
                <html:hidden property="endRadio" value="USER_SPECIFIED" />
              </logic:equal>

              <bvhtml:date name="delegationEditForm" property="end"
                 onChangeMonth="onChangeMonth"
onChangeYear="onChangeYear" noblank="true"/>
              <a href="JavaScript:datePopup(
                  '<html:rewrite page="/mt/calendar.do"/>',
                  'delegationEditForm','end')">
                  <img src="<%=request.getContextPath()%>/bp/images/action/calendar.gif"
                      width="22"
                      height="22"
                      alt='<bean:message key="bp.user.userDelegationEdit.chooseDate"  bundle="bp.messages"/>'
                      title='<bean:message key="bp.user.userDelegationEdit.chooseDate"  bundle="bp.messages"/>'
                      border="0"
                      align="absmiddle"/></a>
            </td>
          </tr>
        </table>

        <div class="pageSubtitle">
          <span class="left"><bean:message key="bp.user.userDelegationEdit.pageSubtitle.enterReasons" bundle="bp.messages"/></span>
          <span class="right">&nbsp;</span>
        </div> 

        <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Enter reasons">
          <tr> 
            <td class="label" width="20%">
              <bean:message key="bp.user.userDelegationEdit.label.reasons" bundle="bp.messages"/>
            </td>
            <td class="labelField" colspan="3">
              <logic:equal name="delegationEditView" property="isCurrent" value="false">
                <html:textarea property="description" cols="60" rows="6" /> &nbsp;
              </logic:equal>
              <logic:equal name="delegationEditView" property="isCurrent" value="true">
                <html:hidden property="description" />
                <bean:write name="delegationEditForm" property="description" />
              </logic:equal>
            </td>
          </tr>
        </table>

        <div class="pageButtonWrap" align="right">
          <html:img page="/bp/images/build/transparent.gif" width="10" height="1" border="0" alt=""/>
          <html:button styleClass="inputButton" property="cancelBtn" onclick="bCancel=true; return isFormCancelOK(this.form)">
            <bean:message key="button.cancel" bundle="bp.messages"/>
          </html:button>
          <logic:equal name="delegationEditView" property="isCurrent" value="false">
            <html:submit styleClass="inputButton" property="submitBtn" onclick="bCancel=false; return doNext(this.form)">
              <bean:message key="button.next" bundle="bp.messages"/>
            </html:submit>
          </logic:equal>
          <logic:equal name="delegationEditView" property="isCurrent" value="true">
            <html:submit styleClass="inputButton" property="submitBtn"
onclick="bCancel=false;  return doFinish(this.form);">
              <bean:message key="button.save" bundle="bp.messages"/>
            </html:submit>
          </logic:equal>
        </div>
        <input type="hidden" name="firstHit" value="false" />
    </td>
  </tr>
</table>

</html:form>
